package com.memory.servlet;

import com.memory.dao.impl.UserDaoImpl;
import com.memory.pojo.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;


@WebServlet(urlPatterns = "/SelectBySnoServlet")
public class SelectBySno extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 1.根据id查找学生数据
        UserDaoImpl userDao = new UserDaoImpl();
        String sno = request.getParameter("Sno");
        User user=new User();

        try {
            user = userDao.selectBySno(Integer.parseInt(sno));
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        request.setAttribute("user",user);
        request.getRequestDispatcher("Update.jsp").forward(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}